import java.util.Queue;
import java.util.Stack;
import java.util.LinkedList;

class MyStack {
    Queue<Integer> queueX;
    Queue<Integer> queueY;

    public MyStack() {
        queueX = new LinkedList<>();
        queueY = new LinkedList<>();
    }

    public void push(int x) {
        queueX.offer(x);
        while(!queueY.isEmpty()){
            queueX.offer(queueY.poll());
        }
        Queue<Integer> tem = queueX;
        queueX = queueY;
        queueY = tem;
    }

    public int pop() {
        return queueY.poll();

    }

    public int top() {
        return queueY.peek();

    }

    public boolean empty() {
        return queueX.isEmpty()&&queueY.isEmpty();
    }
}

